package com.example.mysql;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCExample {
    public static void main(String[] args)  throws Exception{
            //1. 注册驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/javaweb";
            String user = "root";
            String password = "123456";
            Connection conn = DriverManager.getConnection(url, user, password);
            String sql = "SELECT * FROM tb_brand";
            Statement statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                String brand_name = resultSet.getString("brand_name");
                String company_name = resultSet.getString("company_name");
                String description = resultSet.getString("description");
                System.out.println("id："+id+" ,brand_name:"+brand_name+" ,company_name:"+company_name+ " ,description:"+description);
            }
            statement.close();
            conn.close();
    }
}
